local TF_APPLE = Class(function(self, inst)
    self.inst       = inst
    self.has_opened = false
    self.has_eaten  = false
end)

local function OnHit(attacker, data)
    local target = data.target
    if target and target:IsValid() and target:HasTag("epic") then
        local truedamage = 10
        if target.components.health ~= nil and not target:HasTag("playerghost") then
            target.components.health:DoDelta(-truedamage, nil, "orange_jam_afflicted", nil, attacker, true) -- 无视防御
        end
        if target.components.health:IsDead() then
            attacker:PushEvent("killed", { victim = target })
            if target.components.combat ~= nil and target.components.combat.onkilledbyother ~= nil then
                target.components.combat.onkilledbyother(target, attacker)
            end
        end
    end
end

function TF_APPLE:OnSave()
    return {
        opened = self.has_opened and true or nil,
        eaten  = self.has_eaten and true or nil,
    }
end

function TF_APPLE:OnLoad(data)
    if data then
        self.has_opened = data.opened or false
        self.has_eaten  = data.eaten or false
        if self.has_eaten then
            self.inst:ListenForEvent("onhitother", OnHit)
        end
    end
end

return TF_APPLE
